package com.xiaowen.tool.threadUtil.ThreadExecutorManager;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created with IntelliJ IDEA.
 * User: yf-wenHao
 * Date: 17/6/1
 * Time: 下午3:18
 */
public class CustomRejectedExecutionHandler implements RejectedExecutionHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(CustomRejectedExecutionHandler.class);
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        // 记录异常
        // 报警处理等
        try {
            LOGGER.error("任务太多 列队已经插入不进去了 !!!!");
            executor.getQueue().put(r);
        } catch (Exception e) {
            LOGGER.error("任务太多 列队已经插入不进去了 !!!! : {}", e);
        }
    }
}
